import pRightIcon from '@/orderSubPack/images/confirmOrder/right-icon.png';
import { Image, View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import React from 'react';
import { connect } from 'react-redux';
import baseStyles from '../action-base.module.scss';

const InvoiceView = ({ invoiceConfig, eInvoiceSelected }) => {
  return (
    <View className={baseStyles.ActionBase}>
      <View className="label">开具发票：</View>
      <View
        className="action"
        onClick={() =>
          invoiceConfig?.commonEnable &&
          Taro.navigateTo({
            url: '/orderSubPack/invoiceManagement/invoiceAssistant/index?tab=title',
          })
        }
      >
        {invoiceConfig?.commonEnable && (
          <>
            <View className="tip omit">{eInvoiceSelected.title || '选择开票抬头'}</View>
            <Image src={pRightIcon} className="icon" />
          </>
        )}

        {!invoiceConfig?.commonEnable && (
          <>
            <View className="tip disabled">不支持开票</View>
            <Image src={pRightIcon} className="icon" />
          </>
        )}
      </View>
    </View>
  );
};

export default connect(({ loading, productCar, giftCard }) => ({
  loading,

  giftCardSelected: productCar.giftCardSelected,
  invoiceConfig: giftCard.invoiceConfig,
  eInvoiceSelected: productCar.eInvoiceSelected,
}))(InvoiceView);
